<?php
/*
	招商中心
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$_SESSION['forward_url']='jy_mzhaoshang/index/';
	$return['setting']=$this->plugin_setting('page');
	$return['ischecklogin']=model('jy_weishop/member')->checklogin('','','','',true);
	$member=$this->model('zhaoshang')->checkmember();
	if($member['status']!=1){
		$return['setting']['agent_title']=$return['setting']['agent_title']?:'商户店长';
		exi('','error','jy_mzhaoshang/apply/');
	}
	$basic=model('core/member')->basic($_SESSION['uid']);
	$member=array_merge($member,$basic);
	if($member['level_id']){
		$member['level']=$this->getcolumn('level',array('uniacid'=>$_SESSION['uniacid'],'id'=>$member['level_id']),'title');
	}else{
		$default_levelset=$this->plugin_setting('default_level');
		$member['level']=$default_levelset['title']?:'普通等级';
	}
	if($member['agent_id']){
		$member['agent']=model('core/member')->basic($member['agent_id']);
	}else{
		$member['agent']=array('nickname'=>'总店');
	}
	$return['member']=$member;
	$return['orderfee']=pdo_getsum('jy_mzhaoshang_order',array('uniacid'=>$_SESSION['uniacid'],'zhaoshangid'=>$member['id']),'order_price');
	$return['ordernum']=pdo_count('jy_mzhaoshang_order',array('uniacid'=>$_SESSION['uniacid'],'zhaoshangid'=>$member['id']));
	$data=array();
	//已结算佣金
	$data['balance_total']=$this->sum('balance',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'money');
	$data['balance_num']=$this->count('balance',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
	$data['merch_num']=$this->count('merch',array('uniacid'=>$_SESSION['uniacid'],'zhaoshangid'=>$member['id']));
	//待结算佣金
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'status'=>array(0,1));
	/*if($this->setting['balance_day']){
		//结算天数
		$time=TIMESTAMP-intval($this->setting['balance_day'])*86400;
		$params['complete_time <']=$time;
	}*/
	$data['commission_1']=$this->sum('commission',$params,'money');
	$data['commission_total']=$this->sum('commission',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'money');
	$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
	$data['commission_totalday']=$this->sum('commission',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'createtime >'=>$daytime),'money');
	$data['balance_totalday']=$this->sum('balance',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'createtime >'=>$daytime),'money');
	$data['credit2inall']=pdo_getsum('core_credit_log',array('type'=>2,'is_add'=>1,'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),'fee');
	$data['credit2inday']=pdo_getsum('core_credit_log',array('type'=>2,'is_add'=>1,'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid'],'createtime >'=>$daytime),'fee');
	$data['credit2outall']=pdo_getsum('core_credit_log',array('type'=>2,'is_add'=>0,'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),'fee');
	$data['credit2outday']=pdo_getsum('core_credit_log',array('type'=>2,'is_add'=>0,'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid'],'createtime >'=>$daytime),'fee');
	$return['data']=$data;
	$return['rank']=$this->plugin_setting('rank');
	$return['orderlist_url']='jy_weishop/order.list/';
	set_html('title',$return['setting']['agent_center']?:'商户店长中心');
	exi($return);
}
?>